package action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import service.ICommentService;
import service.IInfoService;
import service.IUserService;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import domain.Information;
import domain.User;

public class Main extends ActionSupport {
	
	private IUserService userService;
	private IInfoService infoService;
	private ICommentService commentService;
	private String userId;
	private String userName;
	private Map<String, List<Information>> informations = new HashMap<String, List<Information>>();
	
	public String execute() throws Exception {
		Map session = ActionContext.getContext().getSession();
		String userId = (String) session.get("userId");
		
		if(userId != null) {
			this.userId = userId;
			User user = userService.getUserByID(userId);
			userName = user.getUserName();
		}
		
		List<Information> infos = infoService.getAllInfo();
		for(int i = 0 ; i < infos.size(); i++) {
			informations.put(infos.get(i).getTitle(), infos);
		}
		return SUCCESS;
	}

	public IUserService getUserService() {
		return userService;
	}

	public void setUserService(IUserService userService) {
		this.userService = userService;
	}

	public IInfoService getInfoService() {
		return infoService;
	}

	public void setInfoService(IInfoService infoService) {
		this.infoService = infoService;
	}

	public ICommentService getCommentService() {
		return commentService;
	}

	public void setCommentService(ICommentService commentService) {
		this.commentService = commentService;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public Map<String, List<Information>> getInformations() {
		return informations;
	}

	public void setInformations(Map<String, List<Information>> informations) {
		this.informations = informations;
	}
	
	
}
